#ifndef _DOUBLELINKLIST_H_
#define _DOUBLELINKLIST_H_

#include <stdbool.h>
#define ElementType void*

#define INITDLLIST(list) DLlist list;InitDLlist(&list);
//节点
struct DoubleLinkNode
{
    ElementType data;//数据域
    struct DoubleLinkNode *next;//后驱节点指针
    struct DoubleLinkNode *prev;//前驱节点指针
};

typedef struct DoubleLinkNode DLNode;

struct DoubleLinkList     //双向链表
{
    DLNode *head;//链表头指针
    DLNode *tail;//链表尾指针
    int len;//链表长度

};

typedef struct DoubleLinkList DLlist;

DLNode * CreateNode(ElementType element);

//初始化
void InitDLlist(DLlist *list);
//尾插法
void InsertDLlistTail(DLlist *list,ElementType element);
//头插
void InsertDLlistHead(DLlist *list,ElementType element);

//按位置删除
void RemoveByIndex(DLlist *list,int index, void (*freePtr)(ElementType));
//按值删除
void RemoveByElement(DLlist *list,ElementType element, bool (*OperPtr)(ElementType,ElementType),void (*freePtr)(ElementType));

//按位置查找
ElementType* FindByIndex(DLlist *list,int index);
//按值查找
DLlist FindByElement(DLlist *list,ElementType element,bool (*OperPtr)(ElementType,ElementType));

//遍历
void TravelDLlist(DLlist *list,void (*funcptr)(ElementType));

//排序
void DLlistSort(DLlist *list,bool (*funcPtr)(ElementType,ElementType));

//清空双向链表
void ClearDLlist(DLlist *list,void (*clearPtr)(ElementType));
#endif